<?php

$output = array(
    "attempted" => $attempted,
    "completed" => $completed,
    "error" => $error,
    "alreadyRunning" => $alreadyRunning,
);

if ($completed && isset($run)) {
    $output["runId"] = $run->getId();
    $output["startDate"] = $run->getStartDate();
    $output["endDate"] = $run->getEndDate();
    $output["duration"] = strtotime($run->getEndDate()) - strtotime($run->getStartDate());
    
    if (isset($addedCount)) {
        $output["addedCount"] = $addedCount;
    }
}

echo json_encode($output);
